<?php
namespace bdd;

class Connection {

	private $_link;

    public static function getConnection() {
        static $conn = null;
        if ($conn == null)
            $conn = new Connection();
        return $conn;
    }	
	
	private function __construct()
	{
		$pass = null;
		$param = \api\arrayFromIni('parametres', __NAMESPACE__);
	
		
	
		$dsn = $param[APIMODE]['sgbd'] . ':dbname=' . $param[APIMODE]['base'] . ';host=' . $param[APIMODE]['host'];
		$user = $param[APIMODE]['user'];
		
		if(isset($param[APIMODE]['password'])) {
			$pass = $param[APIMODE]['password'];
		}
		
		\api\debug\Printer::prints($dsn);
		
		try {
			$this->_link = new \PDO($dsn, $user);
		} catch (\PDOException $e) {
			throw new \Exception('Connexion échouée: ' . $e->getMessage());
		}

	}
	
	public function QueryClassement($limit = false, $offset = false) {
		$sql =  "SELECT mat, pseudo, race, grade, xp FROM persos ORDER BY xp DESC";
		return $this->_link->query($sql);
	}
	
	
}

?>